<?php
/**
 * Created by JetBrains PhpStorm.
 * User: miaodb
 * Date: 11-11-2
 * Time: 上午10:01
 * To change this template use File | Settings | File Templates.
 */

class CLI_Updatenickname extends CLI
{
    public function main()
    {
        cli::output("start:\n");
        $select = DB::select()->from("tc_account")->where('type','=',0);
        $iterator = new Db_Iterator($select, 'default', 10);
        $i = 0;
        while ($iterator->valid())
        {
            // 遍历数据
            foreach ($iterator->current() as $account)
            {
                $accountId = $account['id'];
                $memberId = $account['member_id'];
                $accountNick = $account['nickname'];
                $memberNick = DB::select('nickname')->from('members')->where('member_id','=',$memberId)->fetch_one();

                if($accountNick != $memberNick)
                {
                    echo "account_id:$accountId,member_id:$memberId \n";
                    $i++;
                }


//                $trade_id = DB::select('trade_id')->from('tc_account_detail')->where('account_id','=',$accountId)->where('trade_id','!=',0)->fetch_one();
//                if($trade_id)
//                {
//                    $nickname = DB::select('buyer_nick')->from('tc_trade')->where('id','=',$trade_id)->fetch_one();
//                    if($nickname and $nickname != $account['nickname'])
//                    {
//                        echo "account_id:$accountId,trade_id:$trade_id \n";
//                        DB::update('tc_account')->set(array('nickname' => $nickname))->where('id', '=', $accountId)->execute();
//                        DB::update('members')->set(array('nickname'=>$nickname))->where('member_id','=',$memberId)->execute();
//                        $i++;
//                    }
//                }
            }
            $iterator->next();
            echo '>';
        }
        echo "total:$i";


    }
}